package testcase;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;

import org.junit.Test;

import exceptiondates.*;
import junit.framework.TestCase;

public class TestExceptionDates extends TestCase{
	
	//Test ExceptionDates
	@Test
	public void testExpcetionDates(){
		class TestExceptionDate extends ExceptionDates{

			@Override
			protected void addDates() throws ParseException{
				dates.add(df.parse("09 09 2014"));
			}
			
		}
		TestExceptionDate t = new TestExceptionDate();
		ArrayList<Date> result = t.getList();
		Date target = result.get(0);
		assertEquals(result.size(), 1);
		assertEquals(target.getTime(), 1410192000000L);
	}
	
	//Test wrong exceptionDates
	public void testWrongExpcetionDates(){
		class TestExceptionDate extends ExceptionDates{

			@Override
			protected void addDates() throws ParseException{
				dates.add(df.parse("09 09, 2014"));
			}
			
		}
		TestExceptionDate t = new TestExceptionDate();
		ArrayList<Date> result = t.getList();
		assertEquals(result.size(), 0);
	}

	//Test ExceptionDatesDecorator
	public void testExceptionDatesDecorator(){
		class TestExceptionDateDecorated extends ExceptionDates{

			@Override
			protected void addDates() throws ParseException{
				dates.add(df.parse("09 09 2014"));
			}
			
		}
		class TestExceptionDateDecorator extends ExceptionDatesDecorator{
			public TestExceptionDateDecorator(ExceptionDates decorated){
				super(decorated);
			}

			@Override
			protected void addDates() throws ParseException{
				dates.add(df.parse("09 10 2014"));
			}
			
		}
		ExceptionDates ed = new TestExceptionDateDecorator(new TestExceptionDateDecorated());
		long output1 = 1410192000000L;
		long output2 = 1410278400000L;
		for(Date d : ed.getList())
			assertEquals((d.getTime() == output1 || d.getTime() == output2), true);
	}
}
